<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备编码" prop="deviceSn">
        <el-input
          v-model="queryParams.deviceSn"
          placeholder="请输入设备编码"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="设备编码" align="center" prop="deviceSn" fixed="left" width="150px"/>
      <el-table-column label="片区" align="center" prop="parklotName"  fixed="left" width="150px" show-overflow-tooltip />
      <el-table-column label="泊位号" align="center" prop="placenum"  fixed="left" width="100px"/>

      <el-table-column v-for="(item,index) in formTableList" :key="index" :label="item.label" align="center" :prop="item.prop" width="150px"/>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(row)"
            v-hasPermi="['system:faMriParam:edit']"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item v-for="(item,index) in formTableList" :key="index" :label="item.label" :prop="item.prop">
          <el-input v-model="form[item.prop]" :placeholder="`请输入${item.label}`" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getList, editAndSendParam} from "@/api/parking/equStatRepRecord";
export default {
  name: "EquStatRepRecord",
  dicts: ['project_push_type'],
  data() {
    return {
      formTableList:[
        {label:'雷达驶出阈值',prop:'psrtos'},{label:'磁场阈值',prop:'psmts'},{label:'卡尔曼参数',prop:'psmns'},
        {label:'数据发送失败延时',prop:'pssfd'},{label:'磁场有效次数',prop:'psmdtNvc'},{label:'雷达覆盖阈值',prop:'pirct'},
        {label:'磁场触发阈值',prop:'pimdtTs'},{label:'磁场驶出阈值',prop:'psemTs'},{label:'磁场触发有效次数',prop:'pimdtVc'},
        {label:'红外检测开关',prop:'pbirc'},{label:'心跳间隔',prop:'piht'},{label:'光感触发阈值',prop:'pildtTs'},
        {label:'光感触发有效次数',prop:'pildtVs'},{label:'雷达有效次数',prop:'pirvc'},{label:'雷达故障时间阈值',prop:'pirft'},
        {label:'雷达峰值位置开关',prop:'pbrps'},{label:'雷达采样间隔时间',prop:'pirsi'},{label:'蓝牙开关',prop:'pbble'},
        {label:'光感强制驶出开关',prop:'pblfs'},{label:'重检间隔',prop:'piri'},{label:'重检次数',prop:'pirc'},
        {label:'峰值起点',prop:'pispi'},{label:'雷达驶入阈值',prop:'psrts'},
      ],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceSn: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [{ required: true, message: "项目名称不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    this.formTableList.map(item=>{
      this.rules[item.prop] = [{ required: true, message: `${item.label}不能为空`, trigger: "blur" }]
    })
    this.getList();
  },
  methods: {
    /** 查询字典类型列表 */
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      getList(queryParams).then(response => {
          this.list = response.rows || [];
          this.total = response.total || 0;
          this.loading = false;
        }
      );
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      this.reset();
      this.open = true;
      this.title = "修改地磁设备参数";
      this.form = {...row}
    },
    getStrNull(str){//判断是否为空
      return str === '' || str === null || str === undefined
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let form = {...this.form}
          editAndSendParam(form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
  }
};
</script>